﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace HostWpfDemo
{
    public partial class MainViewModel : ObservableObject
    {
        private readonly ILogger logger;
        private readonly IConfiguration config;

        public MainViewModel(ILogger<MainViewModel> logger, IConfiguration configuration)
        {
            this.logger = logger;
            this.config = configuration;
            logger.LogInformation("主窗口已创建");
        }
        [ObservableProperty]
        private string info;
        [RelayCommand]
        public void ShowInfo(string info)
        {
            var someConfig = config["Logging:LogLevel:Default"];
            logger.LogInformation("读取配置: {SomeConfig}", someConfig);
            Info = someConfig ?? "未能读取配置文件";
        }
    }
}
